import project.TabTextArea;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

public class Form {
    public static void main(String args[]) {
        JFrame frame = new JFrame("SpringLayout");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        JScrollPane scroll = new JScrollPane();
        Container contentPane = frame.getContentPane();

        //主panel
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new FlowLayout());
        for(int i =0;i<100;i++){

            mainPanel.add(new JButton("按钮" + i));
        }
        //设置容器大小
        mainPanel.setPreferredSize(new Dimension(mainPanel.getWidth(), 1500));
        scroll.setPreferredSize(new Dimension(500,500));
        scroll.setViewportView(mainPanel);
        contentPane.add(scroll);
        frame.setSize(500, 600);
        frame.setVisible(true);
    }
    private static void createGUI() throws IOException {
        Frame frame = new Frame("记事本");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        frame.setSize(1000,600);
    }



}
    class Frame extends JFrame {
        public Frame(String title) {
            super(title);
            Container container = getContentPane();
            container.setLayout(new BorderLayout());
//            TabTextArea textArea = new TabTextArea("111");
//            container.add(textArea);
            JPanel panel = new JPanel(new FlowLayout());
            for (int i = 0; i < 10000; i++) {
                JButton btn = new JButton("i" + "");
                panel.add(btn);
            }

            


//            JPanel panel = new JPanel(new FlowLayout());
//            JButton button = new JButton("11");
//            for (int i = 0; i < 1000000; i+=100) {
//                button = new JButton(i + "");
//                panel.add(button);
//            }
            JScrollPane jScrollPane = new JScrollPane(panel);
            int num = container.getComponentCount();
            panel.setPreferredSize(new Dimension(650,50*num));//根据内容更新尺寸
            panel.updateUI();
            //设置垂直滚动条一直出现
            jScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            //设置水平滚动条从不出现
            jScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            container.add(jScrollPane);

        }


    }
